package board_mvc.handler;

import java.io.UnsupportedEncodingException;
import java.sql.Timestamp;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import board.BoardDBBean;
import board.BoardDataBean;
@Controller
public class WriteProAction implements CommandHandler {
	@Resource( name="instance" )
	BoardDBBean dao;
	@RequestMapping("writePro")
	@Override
	public ModelAndView process(HttpServletRequest request,
		HttpServletResponse response) {
	
		try {
			request.setCharacterEncoding( "euc-kr" );
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}	
		
		BoardDataBean dto = new BoardDataBean();
		dto.setNum(Integer.parseInt(request.getParameter("num")));
		dto.setWriter(request.getParameter("writer"));
		dto.setEmail(request.getParameter("email"));
		dto.setSubject(request.getParameter("subject"));
		dto.setPasswd(request.getParameter("passwd"));
		dto.setRef(Integer.parseInt(request.getParameter("ref")));
		dto.setRe_step(Integer.parseInt(request.getParameter("re_step")));
		dto.setRe_level(Integer.parseInt(request.getParameter("re_level")));
		dto.setReg_date(new Timestamp(System.currentTimeMillis()));
		dto.setIp(request.getRemoteAddr());
		dto.setContent(request.getParameter("content"));
		
		// BoardDBBean dao=BoardDBBean.getInstance();
		int result = dao.insertArticle(dto);
			
		return new ModelAndView("writePro","result",result);
	}

}
